#include "MainWindow.h"
#include "InputMgr.h"
#include "Octree.h"
#include "World.h"
#include "Shobjidl.h"
#include "ProgressBar.h"
#include "DXMgr.h"
#include "MainSubject.h"
#include "Event.h"
#include "TerrainWindow.h"

//Menu Items
#define ID_NEW_ITEM			1001
#define ID_OPEN_ITEM        1002
#define ID_SAVE_ITEM		1017
#define ID_SAVEAS_ITEM		1016
#define ID_CLOSE_ITEM       1003
#define ID_EXIT_ITEM        1004
#define ID_WIREFRAME_ITEM   1005
#define ID_OCTREE_ITEM		1006
#define ID_PLAYER_ITEM		1007
#define ID_LEVEL_ITEM		1008
#define ID_ABOUT_ITEM		1009
#define ID_CAMERA1_ITEM		1010
#define ID_CAMERA2_ITEM		1011
#define ID_BIRD_ITEM		1012
#define ID_DWARF_ITEM		1013
#define ID_TIGER_ITEM		1014
#define ID_TREE_ITEM		1015
#define ID_BRUSHSIZE_ITEM	1016
#define ID_BRUSHSHAPE_ITEM	1017
#define ID_SCALE_ITEM		1018
#define ID_ROTATION_ITEM	1019
#define ID_TERRAINEDIT_ITEM	1020
#define ID_MESHEDIT_ITEM	1021
#define ID_PARTICLEEDIT_ITEM 1022
#define ID_TOOLBAR_ITEM		1023
#define ID_TOOLBOX_ITEM		1024
#define ID_PROPERTIES_ITEM	1025
#define ID_HELP_ITEM		1026
#define ID_PLAY_ITEM		1027

//Window Splitter
#define LEFT_WINDOW_WIDTH	200
#define RIGHT_WINDOW_WIDTH	245
#define TOOLBAR_HEIGHT		26
#define STATUSBAR_HEIGHT	26

MainWindow::MainWindow()
: m_leftWindowWidth(200)
, m_pProgressBar(NULL)
, m_pTerrainWindow(NULL)
{
	m_pProgressBar = new ProgressBar();
	m_pProgressBar->SetRange(0, 100);
	m_pProgressBar->SetStep(1);
}
MainWindow::~MainWindow()
{
	if(m_pProgressBar)
	{
		delete m_pProgressBar;
		m_pProgressBar = NULL;
	}
	if(m_pTerrainWindow)
	{
		delete m_pTerrainWindow;
		m_pTerrainWindow = NULL;
	}
}

bool MainWindow::Setup(HWND a_parent, HINSTANCE a_hInst, int a_xPos, int a_yPos, int a_width, int a_height, char* a_pWindowName, char* a_pClassName, DWORD a_style)
{
	WNDCLASS wndClass;
	ZeroMemory(&wndClass, sizeof(WNDCLASS));

	wndClass.cbClsExtra = NULL;
	wndClass.cbWndExtra = sizeof(Controller*);
	wndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndClass.hInstance = a_hInst;
	wndClass.lpfnWndProc = Controller::WndProc;
	wndClass.lpszMenuName = NULL;
	wndClass.style = CS_DROPSHADOW;
	wndClass.lpszClassName = a_pClassName;

	if(!RegisterClass(&wndClass))
	{
		return false;
	}

	m_hWnd = CreateWindowEx(NULL, a_pClassName, a_pWindowName, a_style, a_xPos, a_yPos, a_width, a_height, a_parent, NULL, a_hInst, (LPVOID)this);
	if(m_hWnd == NULL)
	{
		return false;
	}
	UpdateWindow(m_hWnd);
	ShowWindow(m_hWnd, SW_SHOW);

	//Create toolbar - must be made after the window
	if(!CreateWindowToolbar())
	{
		MessageBox(NULL, "Failed to Create toolbar!", "Fail!", MB_OK | MB_ICONEXCLAMATION);
		return false;
	}
	//Create status bar - must be made after the window
	if(!CreateWindowStatusbar())
	{
		MessageBox(NULL, "Failed to Create Status bar!", "Fail!", MB_OK | MB_ICONEXCLAMATION);
		return false;
	}
	//Create menu - must be made after the window
	if(!CreateWindowMenu())
	{
		MessageBox(NULL, "Failed to Create Menu!", "Fail!", MB_OK | MB_ICONEXCLAMATION);
		return false;
	}

	return true;
}
bool MainWindow::CreateWindowMenu()
{
	HMENU hMenu = CreateMenu();
	HMENU hSubMenu = CreatePopupMenu();
	HMENU hRecentMenu = CreatePopupMenu();

	AppendMenu(hSubMenu, MF_STRING, ID_NEW_ITEM, "&New");
	AppendMenu(hSubMenu, MF_STRING, ID_OPEN_ITEM, "&Open");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_SAVE_ITEM, "&Save");
	AppendMenu(hSubMenu, MF_STRING, ID_SAVEAS_ITEM, "Save &As");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);

	AppendMenu(hRecentMenu, MF_STRING, ID_CLOSE_ITEM, "&1.../Level1.war");
	AppendMenu(hRecentMenu, MF_STRING, ID_CLOSE_ITEM, "&2.../Level2.war");
	AppendMenu(hRecentMenu, MF_STRING, ID_CLOSE_ITEM, "&3.../Level3.war");
	AppendMenu(hSubMenu, MF_STRING | MF_POPUP, (UINT)hRecentMenu, "&Recent Items..");

	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_CLOSE_ITEM, "&Close");

	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_EXIT_ITEM, "&Exit");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");

	hSubMenu = CreatePopupMenu();
	AppendMenu(hSubMenu, MF_STRING | MF_USECHECKBITMAPS, ID_WIREFRAME_ITEM, "&Wireframe Rendering");
	AppendMenu(hSubMenu, MF_STRING, ID_OCTREE_ITEM, "&Octree Enable");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_CAMERA1_ITEM, "Camera &1");
	AppendMenu(hSubMenu, MF_STRING, ID_CAMERA2_ITEM, "Camera &2");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_BIRD_ITEM, "Flying &Tiger");
	AppendMenu(hSubMenu, MF_STRING, ID_DWARF_ITEM, "Dwarf");
	AppendMenu(hSubMenu, MF_STRING, ID_TIGER_ITEM, "Tiger");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_TREE_ITEM, "Spawn Another Tree");

	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Options");

	hSubMenu = CreatePopupMenu();
	AppendMenu(hSubMenu, MF_STRING, ID_BRUSHSIZE_ITEM, "&Brush Size");
	AppendMenu(hSubMenu, MF_STRING, ID_BRUSHSHAPE_ITEM, "Brush &Shape");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_SCALE_ITEM, "Apply Scale");
	AppendMenu(hSubMenu, MF_STRING, ID_ROTATION_ITEM, "Apply Rotations");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Tools");

	hSubMenu = CreatePopupMenu();
	AppendMenu(hSubMenu, MF_STRING, ID_TERRAINEDIT_ITEM, "&Terrain Editor");
	AppendMenu(hSubMenu, MF_STRING, ID_MESHEDIT_ITEM, "&Mesh Editor");
	AppendMenu(hSubMenu, MF_STRING, ID_PARTICLEEDIT_ITEM, "&Particle Editor");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Advanced");

	hSubMenu = CreatePopupMenu();
	AppendMenu(hSubMenu, MF_STRING | MF_CHECKED, ID_TOOLBAR_ITEM, "&Toolbar");
	AppendMenu(hSubMenu, MF_STRING | MF_CHECKED, ID_TOOLBOX_ITEM, "Tool &Box");
	AppendMenu(hSubMenu, MF_STRING | MF_CHECKED, ID_PROPERTIES_ITEM, "&Properties Box");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Window");

	hSubMenu = CreatePopupMenu();
	AppendMenu(hSubMenu, MF_STRING, ID_HELP_ITEM, "&Editor Help");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_ABOUT_ITEM, "&About");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");

	SetMenu(m_hWnd, hMenu);

	return true;
}
bool MainWindow::CreateWindowToolbar()
{
	m_hToolbar = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | TBSTYLE_TOOLTIPS | CCS_NODIVIDER, 0, 0, 0, 0, m_hWnd, NULL, GetModuleHandle(NULL), NULL);
	if(m_hToolbar == NULL)
	{
		return false;
	}
	SendMessage(m_hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

	TBBUTTON tbb[17];
	TBADDBITMAP tbab;

	tbab.hInst = HINST_COMMCTRL;
	tbab.nID = IDB_STD_SMALL_COLOR;
	SendMessage(m_hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbab);

	ZeroMemory(tbb, sizeof(tbb));
	tbb[0].iBitmap = STD_FILENEW;
	tbb[0].fsState = TBSTATE_ENABLED;
	tbb[0].fsStyle = BTNS_BUTTON;
	tbb[0].idCommand = ID_NEW_ITEM;
	tbb[0].iString = (INT_PTR)"New";

	tbb[1].iBitmap = STD_FILEOPEN;
	tbb[1].fsState = TBSTATE_ENABLED;
	tbb[1].fsStyle = BTNS_BUTTON;
	tbb[1].idCommand = ID_OPEN_ITEM;
	tbb[1].iString = (INT_PTR)"Open";

	tbb[2].fsStyle = BTNS_SEP;

	tbb[3].iBitmap = STD_FILESAVE;
	tbb[3].fsState = TBSTATE_ENABLED;
	tbb[3].fsStyle = BTNS_BUTTON;
	tbb[3].idCommand = ID_SAVE_ITEM;
	tbb[3].iString = (INT_PTR)"Save";

	tbb[4].iBitmap = STD_FILESAVE;
	tbb[4].fsState = TBSTATE_ENABLED;
	tbb[4].fsStyle = BTNS_BUTTON;
	tbb[4].idCommand = ID_SAVEAS_ITEM;
	tbb[4].iString = (INT_PTR)"Save As";

	tbb[5].iBitmap = STD_DELETE;
	tbb[5].fsState = TBSTATE_ENABLED;
	tbb[5].fsStyle = BTNS_BUTTON;
	tbb[5].idCommand = ID_CLOSE_ITEM;
	tbb[5].iString = (INT_PTR)"Close";

	tbb[6].iBitmap = STD_CUT;
	tbb[6].fsState = TBSTATE_ENABLED;
	tbb[6].fsStyle = BTNS_BUTTON;
	//tbb[6].idCommand = ID_CLOSE_ITEM;
	tbb[6].iString = (INT_PTR)"Cut";

	tbb[7].iBitmap = STD_COPY;
	tbb[7].fsState = TBSTATE_ENABLED;
	tbb[7].fsStyle = BTNS_BUTTON;
	//tbb[7].idCommand = ID_CLOSE_ITEM;
	tbb[7].iString = (INT_PTR)"Copy";

	tbb[8].iBitmap = STD_PASTE;
	tbb[8].fsState = TBSTATE_ENABLED;
	tbb[8].fsStyle = BTNS_BUTTON;
	//tbb[8].idCommand = ID_CLOSE_ITEM;
	tbb[8].iString = (INT_PTR)"Paste";

	tbb[9].iBitmap = STD_UNDO;
	tbb[9].fsState = TBSTATE_ENABLED;
	tbb[9].fsStyle = BTNS_BUTTON;
	//tbb[9].idCommand = ID_CLOSE_ITEM;
	tbb[9].iString = (INT_PTR)"Undo";

	tbb[10].iBitmap = STD_REDOW;
	tbb[10].fsState = TBSTATE_ENABLED;
	tbb[10].fsStyle = BTNS_BUTTON;
	//tbb[10].idCommand = ID_CLOSE_ITEM;
	tbb[10].iString = (INT_PTR)"Redo";

	tbb[11].iBitmap = STD_PRINTPRE;
	tbb[11].fsState = TBSTATE_ENABLED;
	tbb[11].fsStyle = BTNS_BUTTON;
	//tbb[11].idCommand = ID_CLOSE_ITEM;
	tbb[11].iString = (INT_PTR)"Print Preview";

	tbb[12].iBitmap = STD_PROPERTIES;
	tbb[12].fsState = TBSTATE_ENABLED;
	tbb[12].fsStyle = BTNS_BUTTON;
	tbb[12].idCommand = ID_ABOUT_ITEM;
	tbb[12].iString = (INT_PTR)"About";

	tbb[13].iBitmap = STD_HELP;
	tbb[13].fsState = TBSTATE_ENABLED;
	tbb[13].fsStyle = BTNS_BUTTON;
	tbb[13].idCommand = ID_HELP_ITEM;
	tbb[13].iString = (INT_PTR)"Help";

	tbb[14].iBitmap = STD_FIND;
	tbb[14].fsState = TBSTATE_ENABLED;
	tbb[14].fsStyle = BTNS_BUTTON;
	//tbb[14].idCommand = ID_CLOSE_ITEM;
	tbb[14].iString = (INT_PTR)"Find";

	tbb[15].iBitmap = STD_REPLACE;
	tbb[15].fsState = TBSTATE_ENABLED;
	tbb[15].fsStyle = BTNS_BUTTON;
	//tbb[15].idCommand = ID_CLOSE_ITEM;
	tbb[15].iString = (INT_PTR)"Replace";

	tbb[16].iBitmap = STD_PRINT;
	tbb[16].fsState = TBSTATE_ENABLED;
	tbb[16].fsStyle = BTNS_BUTTON;
	tbb[16].idCommand = ID_PLAY_ITEM;
	tbb[16].iString = (INT_PTR)"Play the Level.";

	//This prevents the iString's from being displayed as labels
	SendMessage(m_hToolbar, TB_SETMAXTEXTROWS, 0, 0);

	SendMessage(m_hToolbar, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);

	return true;

}
bool MainWindow::CreateWindowStatusbar()
{
	m_hStatusBar = CreateWindowEx(WS_EX_CLIENTEDGE, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP | WS_CLIPSIBLINGS, 0, 0, 0, 0, m_hWnd, NULL, GetModuleHandle(NULL), NULL);
	if(m_hStatusBar == NULL)
	{
		return false;
	}
	int rightPos[3] = {900,1005,-1};
	SendMessage(m_hStatusBar, SB_SETPARTS, (WPARAM)3, (LPARAM)&rightPos);
	SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Welcome to the Immortal Engine!");

	RECT rect;
	SendMessage(m_hStatusBar, SB_GETRECT, (WPARAM)1, (LPARAM)&rect);

	m_pProgressBar->Setup(m_hStatusBar, GetModuleHandle(NULL), rect.left, rect.top + 1, 100, 18);

	return true;

}
void MainWindow::Update()
{
	//If the popup window is valid, show the menu check box, else dont show it
	if(FindWindow("Right Window", ""))
	{
		CheckMenuItem(GetMenu(FindWindow("Main Window", "Immortal Engine - Level Editor")), ID_PROPERTIES_ITEM, MF_CHECKED);
	}
	else
	{
		CheckMenuItem(GetMenu(FindWindow("Main Window", "Immortal Engine - Level Editor")), ID_PROPERTIES_ITEM, MF_UNCHECKED);
	}
}
void MainWindow::Activate(WPARAM a_wParam)
{
	bool isActive = (a_wParam != WA_INACTIVE);
	//Acquire / unAcquire devices as necessary
	InputMgr::GetInstance().OnActivate(isActive);
}
void MainWindow::Close()
{
	PostQuitMessage(0);
}
void MainWindow::Destroy()
{
	PostQuitMessage(0);
}
void MainWindow::Size(int a_w, int a_h, LPARAM a_lParam)
{
	RECT rect;

	GetClientRect(m_hWnd, &rect);
	HWND left = FindWindowEx(m_hWnd, NULL, "Left Window", NULL);
	HWND right = FindWindowEx(m_hWnd, NULL, "Middle Window", NULL);
	HWND properties = FindWindowEx(m_hWnd, NULL, "Right Window", NULL);

	MoveWindow(left, rect.left, rect.top + TOOLBAR_HEIGHT, rect.left + m_leftWindowWidth, (rect.bottom - rect.top) - STATUSBAR_HEIGHT - TOOLBAR_HEIGHT + 4, true);
	MoveWindow(right, rect.left + m_leftWindowWidth, rect.top + TOOLBAR_HEIGHT, rect.right - (rect.left + m_leftWindowWidth + 245), (rect.bottom - rect.top) - STATUSBAR_HEIGHT - TOOLBAR_HEIGHT + 4, true);
	MoveWindow(properties, rect.right - 245, rect.top + TOOLBAR_HEIGHT, rect.right, (rect.bottom - rect.top) - STATUSBAR_HEIGHT - TOOLBAR_HEIGHT + 4, true);

	//Resize the renderer
	GetClientRect(DXMgr::GetInstance().GetParent(), &rect);
	Renderer::GetInstance().SetDimensions((float)rect.right, (float)rect.bottom);

	SendMessage(m_hStatusBar, WM_SIZE, 0, 0);
	SendMessage(m_hToolbar, WM_SIZE, 0, 0);

}
void MainWindow::Command(int a_id, int a_cmd, LPARAM a_msg)
{
	switch(a_id)
	{
	case ID_NEW_ITEM:
		{
			SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Creating New Level...");
			m_pProgressBar->Reset();
			for(int i=0; i<100; ++i)
			{
				m_pProgressBar->Step();
			}

			SetCursor(LoadCursor(NULL, IDC_WAIT));
			World::GetInstance().Load("media/Level1.war");

			//m_pProgressBar->Reset();

		}
		break;
	case ID_OPEN_ITEM:
		{
			SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Opening...");
			//Create the open file struct
			OPENFILENAME ofn;
			//Output file name, this gives the selected file name from the dialog
			char szFileName[512] = "";
			ZeroMemory(&ofn, sizeof(ofn));

			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = m_hWnd;
			//Filter for the dialog box, filter war files and all files
			ofn.lpstrFilter = "War Files (*.war)\0*.war\0All Files (*.*)\0*.*\0";
			ofn.lpstrFile = szFileName;
			ofn.nMaxFile = 512;
			//Set flags - OFN_NOCHANGEDIR - dont fuck with my directory
			ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
			ofn.lpstrDefExt = "war";

			if(GetOpenFileName(&ofn) != NULL)
			{
				SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Loading Level File...");
				SetCursor(LoadCursor(NULL, IDC_WAIT));
				//Load the level with the selected file name
				World::GetInstance().Load(szFileName);
			}	
		}
		break;
	case ID_SAVE_ITEM:
		{
			SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Saving Level File...");
			World::GetInstance().Save();
		}
		break;
	case ID_SAVEAS_ITEM:
		{
			SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Saving Level File...");
			//Create the save file struct
			OPENFILENAME ofn;

			//Output file name, gives the selected file name to save to
			char szFileName[512] = "";
			ZeroMemory(&ofn, sizeof(ofn));

			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = m_hWnd;
			//Filter for the dialog box, filter war files and all files
			ofn.lpstrFilter = "War Files (*.war)\0*.war\0All Files (*.*)\0*.*\0";
			ofn.lpstrFile = szFileName;
			ofn.nMaxFile = 512;
			//Set flags - OFN_NOCHANGEDIR - dont fuck with my directory
			ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
			ofn.lpstrDefExt = "war";

			if(GetSaveFileName(&ofn) != NULL)
			{
				SetCursor(LoadCursor(NULL, IDC_WAIT));
				//Save the level with the selected file name
				World::GetInstance().SaveLevel(szFileName);
			}
		}
		break;
	case ID_CLOSE_ITEM:
		{
			SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Saving And Closing Level File...");
			SetCursor(LoadCursor(NULL, IDC_WAIT));
			World::GetInstance().Unload();
		}
		break;
	case ID_EXIT_ITEM:
		{
			SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Closing...");
			PostQuitMessage(0);
		}
		break;
	case ID_WIREFRAME_ITEM:
		{
			if(Renderer::GetInstance().GetOctree()->GetWireframeRendering())
				Renderer::GetInstance().GetOctree()->SetWireframeRendering(false);
			else
				Renderer::GetInstance().GetOctree()->SetWireframeRendering(true);
		}
		break;
	case ID_OCTREE_ITEM:
		break;
	case ID_CAMERA1_ITEM:
		{
			Renderer::GetInstance().GetCamera1().Activate(true);
			Renderer::GetInstance().GetCamera2().Activate(false);
			Renderer::GetInstance().GetCamera3().Activate(false);
		}
		break;
	case ID_CAMERA2_ITEM:
		{
			Renderer::GetInstance().GetCamera1().Activate(false);
			Renderer::GetInstance().GetCamera2().Activate(true);
			Renderer::GetInstance().GetCamera3().Activate(false);
		}
		break;
	case ID_BIRD_ITEM:
		{
			Renderer::GetInstance().GetCamera1().Activate(false);
			Renderer::GetInstance().GetCamera2().Activate(false);
			Renderer::GetInstance().GetCamera3().Activate(true);
		}
		break;
	case ID_DWARF_ITEM:
		break;
	case ID_TIGER_ITEM:
		break;
	case ID_TREE_ITEM:
		break;
	case ID_PLAYER_ITEM:
		break;
	case ID_LEVEL_ITEM:
		{

		}
		break;
	case ID_TERRAINEDIT_ITEM:
		{
			if(World::GetInstance().IsLevelLoaded())
			{
				//If one has already been created, then clean up first
				if(m_pTerrainWindow)
				{
					delete m_pTerrainWindow;
					m_pTerrainWindow = NULL;
				}

				m_pTerrainWindow = new TerrainWindow();
				m_pTerrainWindow->Setup(m_hWnd, GetModuleHandle(NULL), 50, 50, 600, 500, "Terrain Editor", "Terrain Editor", WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE);
			}
			else
			{
				//grey it out
				
			}
		}
		break;
	case ID_PROPERTIES_ITEM:
		{
			//Check to see if the window is valid
			/*if(FindWindow(POPUP_CLASS_NAME, "Properties Box"))
			{
			DestroyWindow(g_hPopup);
			}
			else
			{
			CreateWindowPopup();
			}*/
		}
		break;
	case ID_ABOUT_ITEM:
		{
			MessageBox(NULL, "This Awesome Level Editor is brought to you by Grant Johnson.", "About", MB_OK | MB_ICONINFORMATION);
		}
		break;
	}
}
void MainWindow::AfterMessages()
{
	//Reset status bar msg back to default
	SendMessage(m_hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM) "Welcome to the Immortal Engine!");
}
void MainWindow::ContextMenu(HWND a_hWnd, int a_x, int a_y)
{
	/*HMENU hSubMenu = CreatePopupMenu();

	AppendMenu(hSubMenu, MF_STRING, ID_NEW_ITEM, "&New");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_OPEN_ITEM, "&Cut");
	AppendMenu(hSubMenu, MF_STRING, ID_OPEN_ITEM, "&Copy");
	AppendMenu(hSubMenu, MF_STRING, ID_OPEN_ITEM, "&Paste");
	AppendMenu(hSubMenu, MF_MENUBARBREAK, NULL, NULL);
	AppendMenu(hSubMenu, MF_STRING, ID_OPEN_ITEM, "&Properties");

    int command = TrackPopupMenu(hSubMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, a_x, a_y, 0, a_hWnd, 0);
	if(command == ID_NEW_ITEM)
	{
	}
	DestroyMenu(hSubMenu);*/
}
void MainWindow::RButtonDown(WPARAM a_wParam, int a_x, int a_y)
{
	Event pEvent(MainSubject::GetInstance().Hash("R Button Down"));
	MainSubject::GetInstance().NotifyObservers(pEvent);
}